-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sockets - Grace #22
base: master
Are you sure you want to change the base?
Sockets - Grace #22
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, there's a bug with heap_down
, see my comment on it and let me know any questions you have. Otherwise not bad. Also consider recursion and time complexity.
else | ||
min = [left, right].min_by {|x| @store[x].key} | ||
end | ||
swap(index, min) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't quite working because you're not checking to see if the element at index is greater than the element at min.
if @store[index] > @store[min]
swap(index, min)
heap_down(min)
end
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: 0(n log n) | ||
# Space Complexity: 0(1) | ||
def heap_sort(list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not working due to a bug in heap_down
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: 0(log n) | ||
# Space Complexity: 0(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since heap_down
is recursive you have to consider the impact of the recursion on space complexity.
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: 0(log n) | ||
# Space Complexity: 0(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto for heap_up
Heaps Practice
Congratulations! You're submitting your assignment!
Comprehension Questions
heap_up
&heap_down
methods useful? Why?